package com.hmall.util;



import com.aliyun.oss.OSSClient;
import com.hdmall.business.common.util.DateTimeUtil;
import com.hmall.vo.*;
import com.itextpdf.text.*;
import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.*;

public class PdfUtil {
    protected static String endpoint = "http://oss-cn-beijing.aliyuncs.com";
    protected static String accessKeyId  = "LTAIp8OhI23AvQo5";
    protected static String accessKeySecret  = "EaCVFvRhYCNpVDkehMt18TPn8zgpwP";
    protected static String bucketName  = "huangyonghui";
    public static   OSSClient ossClient=new OSSClient(endpoint, accessKeyId, accessKeySecret);
   public static BaseFont bfChinese = null;
  // public static String PDFPATH = "http://47.98.167.99:9090/manage/upload/testuploadimg/";
    public static void main(String[] args)  {
        //orderSalesContPdfUpload("pdf/test2.pdf","打发打发",orderSalesContVo);
    }

    /**
     * 销售合同显示并上传
     * @param title
     * @param orderSalesContVo
     */
    public static MallOrderSalesContVo orderShowSalesContPdfUpload(String ftpFileName, String title, MallOrderSalesContVo orderSalesContVo,
                                               UnitContactVo yiUnit,UnitContactVo jiaUnit){

        Document document = new Document(PageSize.B5, 20, 0, 20, 0);

        try {
            //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(PDFPATH+ftpFileName));
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf/"+ftpFileName));
            //bfChinese= BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
            //Font blueFont = new Font(bfChinese);
            bfChinese = BaseFont.createFont("/usr/share/fonts/lyx/SIMSUN.TTC,1",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
            Font ParaTitlefont=setfont(20);
            document.open();
            Paragraph titlePar = new Paragraph(title, ParaTitlefont);
            titlePar.setAlignment(Element.ALIGN_CENTER);
            document.add(titlePar);
            //加入空行
            Paragraph blankRow1 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow1);
            Font table1Fot=setfont(10);

            PdfPTable table1 = new PdfPTable(new float[] {70,45});// 2列的表格以及单元格的宽度
            table1.setPaddingTop(3);// 顶部空白区高度
            table1.getDefaultCell().setBorder(0);
           // table1.setTotalWidth(360);//表格整体宽度
           /* PdfPCell cell1=new PdfPCell();
            cell1.set*/
            table1.addCell(createCell("供方："+orderSalesContVo.getJiaDeptName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table1.addCell(createCell("合同编号：",table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            document.add(table1);
            PdfPTable table2 = new PdfPTable(new float[] {70,45});
            table2.setPaddingTop(3);// 顶部空白区高度
            table2.getDefaultCell().setBorder(0);
            table2.addCell(createCell("",table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table2.addCell(createCell("签署地点：",table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            document.add(table2);
            PdfPTable table3 = new PdfPTable(new float[] {70,45});
            table3.setPaddingTop(3);// 顶部空白区高度
            table3.getDefaultCell().setBorder(0);
            table3.addCell(createCell("需方:"+orderSalesContVo.getYiDeptName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            String contCreateTime= DateTimeUtil.dateToStr(orderSalesContVo.getCreateTime());
            table3.addCell(createCell("签订时间：",table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            document.add(table3);
            //列表
            Font contClauseListFot=setfont(10);
            List contClauseList = new List(List.ORDERED);
            contClauseList.setIndentationLeft(50);
            for(ContClauseVo contClause:orderSalesContVo.getContClauseVos()){

                contClauseList.add(new ListItem(contClause.getTitle()+":"+contClause.getContent(),contClauseListFot));

            }

            document.add(contClauseList);
            //加入空行
            Paragraph blankRow2 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow2);
            int width4[] = {25,18,16,16,16,19,12};
            PdfPTable table4 = new PdfPTable(7);
            table4.setWidths(width4);
            table4.setPaddingTop(3);// 顶部空白区高度
            table4.getDefaultCell().setBorder(1);
            PdfPCell cellT41=createCell("产品名称",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT42=createCell("产品批号",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT43=createCell("产品等级",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT44=createCell("数量",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT45=createCell("单价",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT46=createCell("金额",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT47=createCell("备注",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            table4.addCell(cellT41);
            table4.addCell(cellT42);
            table4.addCell(cellT43);
            table4.addCell(cellT44);
            table4.addCell(cellT45);
            table4.addCell(cellT46);
            table4.addCell(cellT47);
            OrderSelectVo order= orderSalesContVo.getOrderVo();
            java.util.List<OrderSelectItemVo> itemVos= order.getOrderSelectItemVos();
            //设置产品名字体
            Font pNameFt=setfont(8);
            Integer weightTotal=0;
            for(OrderSelectItemVo item:itemVos){
                weightTotal+=item.getWeight();
                table4.addCell(createCell(item.getProducName(),pNameFt,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getProductModel(),table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getGrade(),table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getWeight()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getCurrentPrice()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getProductTotalPrice()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell("",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            }
            document.add(table4);
            //合计
            int width5[] = {59,16,16,19,12};
            PdfPTable table5 = new PdfPTable(5);
            table5.setWidths(width5);
            table5.setPaddingTop(2);// 顶部空白区高度
            table5.getDefaultCell().setBorder(1);
            table5.addCell(createCell("合计",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell(weightTotal+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell("",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell(order.getPayment()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell("",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            document.add(table5);
            Paragraph blankRow4 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow4);
            int width6[] = {60,55};
            PdfPTable table6 = new PdfPTable(2);
            table6.setWidths(width6);
            table6.setPaddingTop(3);// 顶部空白区高度
            table6.addCell(createCell("供方："+jiaUnit.getUnitName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table6.addCell(createCell("需方："+yiUnit.getUnitName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table6.addCell(createCell("单位地址："+jiaUnit.getUnitName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table6.addCell(createCell("单位地址："+yiUnit.getUnitName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            document.add(table6);
            //加入空行
            Paragraph blankRow5 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow5);
            //加入空行
            Paragraph blankRow6 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow6);
            int width7[] = {60,55};
            PdfPTable table7 = new PdfPTable(2);
            table7.setWidths(width6);
            table7.setPaddingTop(3);// 顶部空白区高度
            table7.addCell(createCell("电话："+jiaUnit.getTel()+"传真："+jiaUnit.getFax(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table7.addCell(createCell("电话："+yiUnit.getTel()+"传真："+yiUnit.getFax(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table7.addCell(createCell("开户银行："+jiaUnit.getBankName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table7.addCell(createCell("开户银行："+yiUnit.getBankName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table7.addCell(createCell("账户："+jiaUnit.getBankAccount(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table7.addCell(createCell("账户："+yiUnit.getBankAccount(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            document.add(table7);

        }
        catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        document.close();
        //上传PDF
     /*   String pdfKey=uploadPdfFile2OSS(in,ftpFileName);
        String pdfUrl=getPdfUrl(pdfKey);
        System.out.println(pdfUrl);*/
        orderSalesContVo.setOrderSalesContPdf(ftpFileName);
        //保存上传pdf地址
        //orderSalesContVo.setOrderSalesContPdf(PDFPATH+ftpFileName);
        return  orderSalesContVo;
    }
    /**
     * 销售合同生成并上传
     * @param title
     * @param orderSalesContVo
     */
    public static MallOrderSalesContVo orderCreateSalesContPdfUpload(String ftpFileName, String title, MallOrderSalesContVo orderSalesContVo,
                                               UnitContactVo yiUnit,UnitContactVo jiaUnit){

        Document document = new Document(PageSize.B5, 20, 0, 20, 0);

        try {
            //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(PDFPATH+ftpFileName));
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf/"+ftpFileName));
            bfChinese = BaseFont.createFont("/usr/share/fonts/lyx/SIMSUN.TTC,1",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
            //Font blueFont = new Font(bfChinese);
            Font ParaTitlefont=setfont(20);
            document.open();
            Paragraph titlePar = new Paragraph(title, ParaTitlefont);
            titlePar.setAlignment(Element.ALIGN_CENTER);
            document.add(titlePar);
            //加入空行
            Paragraph blankRow1 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow1);
            Font table1Fot=setfont(10);

            PdfPTable table1 = new PdfPTable(new float[] {70,45});// 2列的表格以及单元格的宽度
            table1.setPaddingTop(3);// 顶部空白区高度
            table1.getDefaultCell().setBorder(0);
           // table1.setTotalWidth(360);//表格整体宽度
           /* PdfPCell cell1=new PdfPCell();
            cell1.set*/
            table1.addCell(createCell("供方："+orderSalesContVo.getJiaDeptName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table1.addCell(createCell("合同编号："+orderSalesContVo.getSaleContNo(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            document.add(table1);
            PdfPTable table2 = new PdfPTable(new float[] {70,45});
            table2.setPaddingTop(3);// 顶部空白区高度
            table2.getDefaultCell().setBorder(0);
            table2.addCell(createCell("",table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table2.addCell(createCell("签署地点：",table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            document.add(table2);
            PdfPTable table3 = new PdfPTable(new float[] {70,45});
            table3.setPaddingTop(3);// 顶部空白区高度
            table3.getDefaultCell().setBorder(0);
            table3.addCell(createCell("需方:"+orderSalesContVo.getYiDeptName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            String contCreateTime= DateTimeUtil.dateToStr(orderSalesContVo.getCreateTime());
            table3.addCell(createCell("签订时间："+contCreateTime,table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            document.add(table3);
            //列表
            Font contClauseListFot=setfont(10);
            List contClauseList = new List(List.ORDERED);
            contClauseList.setIndentationLeft(50);
            for(ContClauseVo contClause:orderSalesContVo.getContClauseVos()){

                contClauseList.add(new ListItem(contClause.getTitle()+":"+contClause.getContent(),contClauseListFot));

            }

            document.add(contClauseList);
            //加入空行
            Paragraph blankRow2 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow2);
            int width4[] = {25,18,16,16,16,19,12};
            PdfPTable table4 = new PdfPTable(7);
            table4.setWidths(width4);
            table4.setPaddingTop(3);// 顶部空白区高度
            table4.getDefaultCell().setBorder(1);
            PdfPCell cellT41=createCell("产品名称",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT42=createCell("产品批号",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT43=createCell("产品等级",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT44=createCell("数量",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT45=createCell("单价",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT46=createCell("金额",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            PdfPCell cellT47=createCell("备注",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE);
            table4.addCell(cellT41);
            table4.addCell(cellT42);
            table4.addCell(cellT43);
            table4.addCell(cellT44);
            table4.addCell(cellT45);
            table4.addCell(cellT46);
            table4.addCell(cellT47);
            OrderSelectVo order= orderSalesContVo.getOrderVo();
            java.util.List<OrderSelectItemVo> itemVos= order.getOrderSelectItemVos();
            //设置产品名字体
            Font pNameFt=setfont(8);
            Integer weightTotal=0;
            for(OrderSelectItemVo item:itemVos){
                weightTotal+=item.getWeight();
                table4.addCell(createCell(item.getProducName(),pNameFt,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getProductModel(),table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getGrade(),table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getWeight()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getCurrentPrice()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell(item.getProductTotalPrice()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
                table4.addCell(createCell("",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            }
            document.add(table4);
            //合计
            int width5[] = {59,16,16,19,12};
            PdfPTable table5 = new PdfPTable(5);
            table5.setWidths(width5);
            table5.setPaddingTop(2);// 顶部空白区高度
            table5.getDefaultCell().setBorder(1);
            table5.addCell(createCell("合计",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell(weightTotal+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell("",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell(order.getPayment()+"",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            table5.addCell(createCell("",table1Fot,Element.ALIGN_CENTER,Element.ALIGN_MIDDLE));
            document.add(table5);
            Paragraph blankRow4 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow4);
            int width6[] = {60,55};
            PdfPTable table6 = new PdfPTable(2);
            table6.setWidths(width6);
            table6.setPaddingTop(3);// 顶部空白区高度
            table6.addCell(createCell("供方："+jiaUnit.getUnitName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table6.addCell(createCell("需方："+yiUnit.getUnitName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table6.addCell(createCell("单位地址："+jiaUnit.getUnitName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table6.addCell(createCell("单位地址："+yiUnit.getUnitName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            document.add(table6);
            //加入空行
            Paragraph blankRow5 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow5);
            //加入空行
            Paragraph blankRow6 = new Paragraph(18f, " ", ParaTitlefont);
            document.add(blankRow6);
            int width7[] = {60,55};
            PdfPTable table7 = new PdfPTable(2);
            table7.setWidths(width6);
            table7.setPaddingTop(3);// 顶部空白区高度
            table7.addCell(createCell("电话："+jiaUnit.getTel()+"传真："+jiaUnit.getFax(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table7.addCell(createCell("电话："+yiUnit.getTel()+"传真："+yiUnit.getFax(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table7.addCell(createCell("开户银行："+jiaUnit.getBankName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table7.addCell(createCell("开户银行："+yiUnit.getBankName(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table7.addCell(createCell("账户："+jiaUnit.getBankAccount(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            table7.addCell(createCell("账户："+yiUnit.getBankAccount(),table1Fot,Element.ALIGN_LEFT,Element.ALIGN_MIDDLE));
            document.add(table7);

        }
        catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        document.close();
        //上传PDF
     /*   String pdfKey=uploadPdfFile2OSS(in,ftpFileName);
        String pdfUrl=getPdfUrl(pdfKey);
        System.out.println(pdfUrl);*/
        orderSalesContVo.setOrderSalesContPdf(ftpFileName);
        //保存上传pdf地址
        //orderSalesContVo.setOrderSalesContPdf(PDFPATH+ftpFileName);
        return  orderSalesContVo;
    }
   /* public static String uploadPdfFile2OSS(InputStream in, String fileName){
        String key=  OSSClientUtil.uploadPdfFile2OSS(in,fileName);


        //ossClient.getPdfImgUrl(fileName)
    }*/
    /**
     * 上传到pdf OSS服务器  如果同名文件会覆盖服务器上的
     *
     * @param instream 文件流
     * @param fileName 文件名称 包括后缀名
     * @return 出错返回"" ,唯一MD5数字签名
     */
    /*public static String uploadPdfFile2OSS(InputStream instream, String fileName) {
        //String originalFilename = file.getOriginalFilename();
        String substring = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
        Random random = new Random();
        fileName = random.nextInt(10000) + System.currentTimeMillis() + substring;
        String ret = "";
        try {
            //创建上传Object的Metadata
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setContentLength(instream.available());
            objectMetadata.setCacheControl("no-cache");
            objectMetadata.setHeader("Pragma", "no-cache");
            objectMetadata.setContentType(getcontentType(fileName.substring(fileName.lastIndexOf("."))));
            objectMetadata.setContentDisposition("inline;filename=" + fileName);
            //上传文件
            PutObjectResult putResult = ossClient.putObject(bucketName, "pdf/" + fileName, instream, objectMetadata);
            ret = putResult.getETag();
        } catch (IOException e) {
            System.out.println("上传失败！！！");
            return  null;
        } finally {
            try {
                if (instream != null) {
                    instream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }*/
    /**
     * 创建单元格(内容为文字)
     * @param align
     * @return
     */
    public static PdfPCell newPdfPCell(int align,int row,String name,Font font){
        PdfPCell cell=new PdfPCell();
       /* cell.setBorderColor(Color.black);
        cell.setBorderColorLeft(Color.BLACK);
        cell.setBorderColorRight(Color.BLACK);*/
        //cell.setBackgroundColor(bgColor);
        //cell.setBorder(border);
        cell.setHorizontalAlignment(align);
        cell.setRowspan(row);
        cell.addElement(new Paragraph(name,font));
        return cell;
    }
    /**
     * 创建单元格
     * @param name
     * @return
     */
    public static PdfPCell createCell (String name,Font font,int plane,int vertical)  {

        PdfPCell cell = new PdfPCell(new Paragraph(name,font));
       /* cell.setBorderColor(BaseColor.BLUE);//边框验证
        cell.setPaddingLeft(20);//左填充20
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);//水平居中
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);//垂直居中*/
        cell.setHorizontalAlignment(plane);//水平居中
        cell.setVerticalAlignment(vertical);//垂直居中
        return  cell;
    }
    public static Font setfont(Integer size){
        //中文字体,解决中文不能显示问题

        //蓝色字体
        Font font = new Font(bfChinese);
        //font.setColor(BaseColor.BLUE);
        font.setSize(size);
        //Font FontChinese1 = new Font(bfChinese, size, Font.BOLD);
        //font.setFamily("STSongStd-Light");

        return  font;
    }
    /**
     * 创建一个跨多行的单元格
     * @param rows 所占行数
     * @param align 对齐方式
     */
    public static  PdfPCell newPdfPCellByRows(int rows,String name,int align,Font font){
        PdfPTable iTable=new PdfPTable(1);
        PdfPCell iCell=new PdfPCell();
        iCell.setFixedHeight(iCell.getFixedHeight()*rows);
        iTable.addCell(iCell);
        //iCell.setBackgroundColor(bgColor);
        iCell.addElement(new Paragraph(name,font));
        iCell.setHorizontalAlignment(align);
        PdfPCell cell=new PdfPCell(iTable);
        return cell;
    }

    /**
     * 创建一个跨多列的单元格
     * @param colspan 所占列数
     * @param align 对齐方式
     */
    public static  PdfPCell newPdfPCellByColspan(int colspan,String name,int align,Font font){
        PdfPTable iTable=new PdfPTable(1);
        PdfPCell iCell=new PdfPCell();
        iCell.setColspan(colspan);
        //iCell.setBackgroundColor(bgColor);
        iCell.setBorder(0);
        iCell.addElement(new Paragraph(name,font));
        iCell.setHorizontalAlignment(align);
        iTable.addCell(iCell);
        PdfPCell cell=new PdfPCell(iTable);
        return cell;
    }
}


